﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net.Mail;
using System.Net;
using System.Web.Security;

namespace KidsGest.Models
{
    public class SendEmail
    {
        public static void SendResetEmail(System.Web.Security.MembershipUser user)
        {
            MailMessage email = new MailMessage("quintaguimaraes@kidsgest.com", user.Email);

            email.From = new MailAddress("quintaguimaraes@kidsgest.com");
            email.To.Add(new MailAddress(user.Email));

            email.Subject = "Password Reset";
            String pass = "123456";

            string link = "A sua nova password é: " + pass;
            email.Body = link;
           // email.Body = "<p>" + user.UserName + " please click the following link to reset your password: <a href='" + link + "'>" + link + "</a></p>";
            //email.Body += "<p>If you did not request a password reset you do not need to take any action.</p>";

            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);

            smtpClient.Credentials = new NetworkCredential("bitz.pt@gmail.com", "inovacao");

            //envia o email
            smtpClient.EnableSsl = true;

            smtpClient.Send(email);

            user.ChangePassword(Membership.Provider.GetPassword(user.UserName, String.Empty), pass);
            Membership.UpdateUser(user);
        }

        public static string HashResetParams(string username, string guid)
        {

            byte[] bytesofLink = System.Text.Encoding.UTF8.GetBytes(username + guid);
            System.Security.Cryptography.MD5 md5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            string HashParams = BitConverter.ToString(md5.ComputeHash(bytesofLink));

            return HashParams;
        }

        public static void SendEmailPreRegisto(String nome, String mail)
        {
            MailMessage email = new MailMessage("quintaguimaraes@kidsgest.com", mail);

            email.From = new MailAddress("quintaguimaraes@kidsgest.com");
            email.To.Add(new MailAddress(mail));

            email.Subject = "Confirmação de Pré-Inscrição";
            email.IsBodyHtml = true;

            email.Body = "<p>Caro(a) " + nome + ", o colégio A Quinta Guimarães vem por este meio informar que a sua candidatura foi recebida com sucesso!</p>";
            email.Body += "<p>Dentro de 5 dias úteis irá receber uma nova notificação com o resultado da sua candidatura.</p>";
            email.Body += "<p></p><p>Agradecemos desde já pela sua atenção.</p>";
            email.Body += "<p>Com os melhores cumprimentos,</p>";
            email.Body += "<p></p><h1>A Quinta Guimarães</h1>";

            SmtpClient smtpClient = new SmtpClient("smtp.gmail.com", 25);

            smtpClient.Credentials = new NetworkCredential("bitz.pt@gmail.com", "inovacao");

            //envia o email
            smtpClient.EnableSsl = true;

            smtpClient.Send(email);
        }

    }
}